// 云函数入口文件
const cloud = require("wx-server-sdk");
cloud.init();
const db = cloud.database();

const pick = (data, names) => {
    const newData = {};
    names.forEach((i) => {
        if (i in data) newData[i] = data[i];
    });
    return newData;
};
exports.main = async ({ userInfo, USER }) => {
    return db
        .collection("User")
        .doc(userInfo.openId)
        .update({
            data: pick(USER, ["nickName", "avatarUrl"]),
        });
};
